package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AddOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        System.out.println("添加图书");
        //接收图书信息
        Scanner sc = new Scanner(System.in);
        System.out.println("输入要添加图书的名称");
        String name = sc.nextLine();// 书名

        System.out.println("输入要添加图书的作者");
        String author = sc.nextLine();// 作者

        System.out.println("输入要添加图书的类型");
        String type = sc.nextLine();// 类型

        System.out.println("输入要添加图书的价格");
        int price = sc.nextInt();// 价格
        //先输入Line再输入int


        Book book = new Book(name,author,price,type);
        //判断书架是否已满
        if(bookList.getUsedSize() == 10){
            //书架满了，需要扩容
            bookList.setUsedSize(2 * bookList.getUsedSize());

        }

        bookList.setBook(bookList.getUsedSize(),book);
        int newUsedSize = bookList.getUsedSize() + 1;
        bookList.setUsedSize(newUsedSize);
        System.out.println("添加成功");
    }
}
